﻿import redis


class redis_client:
    def __init__(self, host, port, password, *args, **kwargs):
        pool0 = redis.ConnectionPool(host=host, port=port, password=password, db=0,decode_responses=True)
        pool5 = redis.ConnectionPool(host=host, port=port, password=password, db=4,decode_responses=True)
        pool15 = redis.ConnectionPool(host=host, port=port, password=password, db=13,decode_responses=True)
        self.hit_result = redis.Redis(connection_pool=pool0)
        self.archives_data_pool = redis.Redis(connection_pool=pool5)
        self.specific_data_pool = redis.Redis(connection_pool=pool15)

    # db 0 hit data
    def insert_hit_data(self, list_data):
        self.hit_result.lpush("HIT_RESULT", list_data)

    # db 5 归档数据 ZSET
    def get_all_zset_keys(self):
        return self.archives_data_pool.keys()

    def zset_get_specific_data(self, name):
        return self.archives_data_pool.zrange(name=name, start=0, end=-1, desc=True)

    def zset_get_size(self, name):
        return self.archives_data_pool.zcard(name=name)

    # db 15 详细信息
    def insert_specific_data(self, name, key, value):
        self.specific_data_pool.hset(name, key, value)

    def get_specific_data(self, name):
        return self.specific_data_pool.hgetall(name)


client = redis_client("192.168.1.12", 6379, None)
# print(client.get_specific_data("10"))
# # print(redis_client("192.168.3.35", 6379, 12345678))
# client = redis_client("192.168.3.55", 6379, None)
# keys = client.get_all_zset_keys()
# for key in keys:
#     print(key)
#     print(client.zset_get_specific_data(key))
